package SentenceTranslator;
import Main.SymbolManager;
import Include.ASMConstructor;
import Common.REG;
import Include.TACLine;

import java.util.*;

public class CreatelistTranslator {
    public List<String> asmlines;
    public List<String> SentenceTranslate(SymbolManager SymbolManager_, TACLine TACLine_) {
        asmlines = new ArrayList<String>();
        String array_str_encode = SymbolManager_.encodeVar(TACLine_.src1.value);
        // 这里的int转化不知道会不会出错。。。
        int array_space = 4 * Integer.parseInt(TACLine_.src2.value);
        SymbolManager_.setEspBias(4);
        asmlines.add(ASMConstructor.construct_asm("sub", REG.ESP, String.valueOf(4)));
        int array_ptr_mem = SymbolManager_.get_esp() - 4;
        SymbolManager_.setAvalueMem(array_str_encode, array_ptr_mem);
        SymbolManager_.setEspBias(array_space);
        asmlines.add(ASMConstructor.construct_asm("sub", REG.ESP, String.valueOf(array_space)));
        asmlines.add(ASMConstructor.construct_asm("mov", Integer.valueOf(array_ptr_mem), REG.ESP));

        return asmlines;
    }
}